Let $S_t$ represent the stock price at time $t.$ How to write a simple model for this quantity?
where $S_{t+\delta t}-S_t=\delta S$
In the limit $\delta t\rightarrow 0$, we have $$ \lim_{\delta t\rightarrow 0}\frac{S_{t+\delta t}-S_t}{S_t} = \frac{dS}{S} $$
Return: $$ dS=\mu S_t dt+\sigma S_t dW $$
The notebook contains "cells", and in each cell there is either information (like this) or code (they have "In [ ]" to the left). You can run the code in the notebook, as well as editing and rerunning it. The notebook will work best if you first run each cell in the order they appear. You can then click on a cell and run it again if you have changed anything.
We can observe $S_t$ as recorded on the stock exchange. We can plot a time series of a real stock (the actual stock is unimportant) that I've already downloaded. We now write some code to import the plot into a variable M.
from MathFinanceWorkshop import MFW_plot
M = MFW_plot()
Run the first two cells containging code. You can see the cells with code as they have "In [ ] " to the left. You should see a figure appear below the second command. This plots the timeseries of $S_t$ against. The graph is split into 20 time periods and each are a different colour, the reason will become apparent in the next cell.
M.plotRealData()
Now run the third and final cell containing code. You should see a button "Run Interact" appear below, press it. A figure containing fours graphs will show.
The top left contains the same real data as above but now we have 20 lines on the graph all starting at $S_0=1$, as the data has been scaled against the initial value.
The top right contains the 20 simulations starting at $S_0=1$, using the stock model outlined above and the parameters selected for $\mu$ and $\sigma$.
The bottom left contains a histogram of the historical stock returns, $$ \frac{S_{t+\delta t}-S_t}{S_t} $$ and the bottom right is a histogram of returns for the simulated stock prices. If it is a good model and properly calibrated you should expect the graphs on the left to look like the graphs on the right.
Try moving the sliders to different values of $\mu$ and $\sigma$, can you get the data on the right (our mathematical model) to look like the data on the left?
M.f_plot_interactive()
interactive(children=(FloatSlider(value=0.0, description='mu', max=0.1, min=-0.1, step=0.01), FloatSlider(valu…
<function ipywidgets.widgets.interaction._InteractFactory.__call__.<locals>.<lambda>(*args, **kwargs)>